﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>实时资讯</title>

    <link rel="stylesheet" href="../css/bootstrap.min.css" />
    <script type="text/javascript" src="../js/lib/jquery-1.10.2.min.js" ></script>
     
    <script src="../js/xdate/xdate.js"></script>
    <script src="../js/lodash/lodash.min.js"></script>
</head>
<body> 

    <div >

        <table class="table">

            <tr>
                <td id="tdTime"></td>


            </tr>


        </table>
        <table class="table" id="LAY_demo1">
            <colgroup>
                <col width="10%">
                <col width="90%">
            </colgroup>

            <tbody id="currLoad"></tbody>

        </table>

    </div>
     
</body>
</html>
<script src="../js/mui.min.js"></script>
<script>
    var maxId = 0;
    $(function () {

        $('#tdTime').text(new XDate().toString('yyyy年MM月dd日 HH:mm:ss'));
        setInterval(function () {
            $('#tdTime').text(new XDate().toString('yyyy年MM月dd日 HH:mm:ss'));
        }, 1000);

        getdata(1);
        setInterval(function () {


            //$('#currLoad').html('');
            getCurrData();
        }, 10000);

        //getCurrData();

    });

    function getCurrData() {
        console.log(maxId);
        $.getJSON('http://www.99990158.com/ajax/GetNewsLive4Now.ashx?page=1&maxId=' + maxId, function (rps) {

            if (rps.length > 0) {
                maxId = _.max(rps, function (chr) {
                    return chr.id;
                }).id;

                $.each(rps, function (index, item) {

                    var timestamp3 = item.createdAt;
                    var newDate = new Date();
                    newDate.setTime(timestamp3 * 1000);

                    var a = $('<div>'+item.contentHtml+'</div>');

                    a.removeAttr('href');
                    a.find('a').removeAttr('href');

                    var tbody = $('#currLoad');
                    //if ($('#' + item.id)) { return;}

                    if (a.html().indexOf('黄金') > -1) {
                        tbody.prepend('<tr id="' + item.id + '"><td>' + new XDate(newDate).toString('HH:mm') + '</td><td style="color:red">' + a.html() + '</td></tr>');
                    }
                    else {
                        tbody.prepend('<tr><td>' + new XDate(newDate).toString('HH:mm') + '</td><td>' + a.html() + '</td></tr>');
                    }


                });
            }
            else {

            }
        });
    }
    function getdata(page) {

        $.getJSON('http://www.99990158.com/ajax/GetNewsLive.ashx?page=' + page, function (rps) {
            if (maxId == 0) {
                maxId = _.max(rps, function (chr) {
                    return chr.id;
                }).id;

            }


            $.each(rps, function (index, item) {

                var timestamp3 = item.createdAt;
                var newDate = new Date();
                newDate.setTime(timestamp3 * 1000);

                var a = $('<div>'+item.contentHtml+'</div>');

                a.removeAttr('href');
                a.find('a').removeAttr('href');

                var tbody = $('#currLoad');

                if (a.html().indexOf('黄金') > -1) {
                    tbody.append('<tr id="' + item.id + '"><td>' + new XDate(newDate).toString('HH:mm') + '</td><td style="color:red">' + a.html() + '</td></tr>');
                }
                else {
                    tbody.append('<tr><td>' + new XDate(newDate).toString('HH:mm') + '</td><td>' + a.html() + '</td></tr>');
                }


            });

            //console.log(rps);
        });
    }
    document.addEventListener("swipeleft", function () {
        console.log("你正在向左滑动");
        try {
            window.parent.Change(3);
        } catch (e) {
            console.log(e);
        }
    });
    document.addEventListener("swiperight", function () {
        console.log("你正在向右滑动");
        try {
            window.parent.Change(1);
        } catch (e) {
            console.log(e);
        }
    });
</script>